System.register(["@angular/http", "ng2-layer", "@angular/core", "@angular/router", "@angular/forms", "app/Directives", "@angular/common"], function (exports_1, context_1) {
    "use strict";
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __metadata = (this && this.__metadata) || function (k, v) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
    };
    var __moduleName = context_1 && context_1.id;
    var http_1, ng2_layer_1, core_1, router_1, forms_1, Directives_1, common_1, BoxProductComp, selectImageComp, _a, _b;
    return {
        setters: [
            function (http_1_1) {
                http_1 = http_1_1;
            },
            function (ng2_layer_1_1) {
                ng2_layer_1 = ng2_layer_1_1;
            },
            function (core_1_1) {
                core_1 = core_1_1;
            },
            function (router_1_1) {
                router_1 = router_1_1;
            },
            function (forms_1_1) {
                forms_1 = forms_1_1;
            },
            function (Directives_1_1) {
                Directives_1 = Directives_1_1;
            },
            function (common_1_1) {
                common_1 = common_1_1;
            }
        ],
        execute: function () {
            BoxProductComp = (function () {
                function BoxProductComp(http, router, layer, parent) {
                    var _this = this;
                    this.http = http;
                    this.layer = layer;
                    this.parent = parent;
                    this.products = [];
                    this.product = { status: true };
                    this.selectedImg = {};
                    router.parent.params.subscribe(function (params) {
                        _this.boxId = params.id;
                        _this.loadProduct();
                    });
                }
                BoxProductComp.prototype.loadProduct = function () {
                    var _this = this;
                    this.http.get({
                        search: {
                            m: "Admin",
                            c: "ApiGoods",
                            a: "getGoodsList",
                            box_id: this.boxId
                        }
                    }).then(function (data) {
                        _this.products = data.data.goods_data;
                    });
                };
                BoxProductComp.prototype.showAdd = function () {
                    this.showAddProduct = true;
                    this.product = { status: true };
                    this.selectedImg = {};
                };
                BoxProductComp.prototype.edit = function (p) {
                };
                BoxProductComp.prototype.upOrDown = function (p) {
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiGoods",
                            a: "goodsPutaway"
                        },
                        body: {
                            goods_id: p.goods_id,
                            status: p.status == "0" ? "1" : "0"
                        }
                    }).then(function () {
                        p.status = p.status == "0" ? "1" : "0";
                    });
                };
                BoxProductComp.prototype.deleteProduct = function (p) {
                    var _this = this;
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiGoods",
                            a: "delGoods"
                        },
                        body: {
                            goods_id: p.goods_id
                        }
                    }).then(function () {
                        _this.products = _this.products.filter(function (g) {
                            return g != p;
                        });
                    });
                };
                BoxProductComp.prototype.updateGoodCategory = function (p) {
                };
                BoxProductComp.prototype.addProduct = function () {
                    var _this = this;
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiGoods",
                            a: "addGoods"
                        },
                        body: {
                            name: this.product.name,
                            price: this.product.price,
                            price_cost: this.product.price_cost,
                            innage: this.product.innage,
                            intro: this.product.content,
                            status: this.product.status ? 1 : 0,
                            img_list: this.selectedImg.image_id,
                            box_id: this.boxId,
                            open_innage_tip: 1,
                            min_innage: 1
                        }
                    }).then(function () {
                        _this.showAddProduct = false;
                        _this.loadProduct();
                    });
                };
                BoxProductComp.prototype.selectImages = function () {
                    this.layer.dialog({
                        title: "选择产品图标",
                        parent: this.parent,
                        dialogComponent: selectImageComp,
                        imports: [forms_1.FormsModule, Directives_1.DirectivesM, common_1.CommonModule],
                        data: { parent: this }
                    });
                };
                return BoxProductComp;
            }());
            BoxProductComp = __decorate([
                core_1.Component({
                    selector: '.box_product',
                    templateUrl: 'template/router/boxProduct/product.html'
                }),
                __metadata("design:paramtypes", [http_1.Http, router_1.ActivatedRoute, typeof (_a = typeof ng2_layer_1.NgLayer !== "undefined" && ng2_layer_1.NgLayer) === "function" && _a || Object, core_1.ViewContainerRef])
            ], BoxProductComp);
            exports_1("BoxProductComp", BoxProductComp);
            selectImageComp = (function () {
                function selectImageComp(http, ly) {
                    this.http = http;
                    this.ly = ly;
                    this.images = [];
                }
                selectImageComp.prototype.ngOnInit = function () {
                    if (this.parent.product.name) {
                        this.keyWord = this.parent.product.name;
                        this.search();
                    }
                };
                selectImageComp.prototype.search = function () {
                    var _this = this;
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiGoods",
                            a: "getImageListByKey"
                        },
                        body: {
                            keyword: this.keyWord,
                            count: 100,
                            page: 1
                        }
                    }).then(function (data) {
                        _this.images = data.data;
                    });
                };
                selectImageComp.prototype.select = function (img) {
                    this.selectedImg = img;
                };
                selectImageComp.prototype.apply = function () {
                    this.parent.selectedImg = this.selectedImg;
                    this.ly.close();
                };
                return selectImageComp;
            }());
            selectImageComp = __decorate([
                core_1.Component({ templateUrl: "template/router/boxProduct/selectImages.html" }),
                __metadata("design:paramtypes", [http_1.Http, typeof (_b = typeof ng2_layer_1.NgLayerRef !== "undefined" && ng2_layer_1.NgLayerRef) === "function" && _b || Object])
            ], selectImageComp);
        }
    };
});
